<template>
    <div class="login-input-container">
        <div style="height: 30px">
            <label :class="{'active':isActive}">{{ label }}</label>
        </div>
        <input @focus="activeInput" @blur="backInput(this)" :type="type" @input="changeInput">
    </div>
</template>

<script>
import {ref} from "vue";

export default {
    name: "loginInput",
    props:['label','type'],
    emits:['model'],
    setup(props, context) {
        let isActive = ref(false)

        function activeInput() {
            isActive.value = true
        }

        function backInput(that) {
            if (that.$el.children[1].value !== '') {
                isActive.value = true
            } else {
                isActive.value = false
            }
        }

        function changeInput() {
            context.emit('model',event.target.value)
        }

        return {
            isActive,
            activeInput,
            backInput,
            changeInput,
        }
    }
}
</script>

<style scoped>
.login-input-container {
    width: 80%;
    height: 70px;
    position: relative;
}

label {
    left: 20px;
    top: 38px;
    position: absolute;
    color: grey;
    transition: all 300ms ease-in-out;
    pointer-events: none;
}

label.active {
    top: 3px;
    color: black;
}

input {
    border: none;
    outline: none;
    border-radius: 20px;
    padding: 5px 20px;
    width: calc(100% - 40px);
    height: 30px;
    background-color: #efefef;
}
</style>